package com.sunny.ynhz.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sunny.ynhz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by luao on 2017/6/26.
 */

public class AddProblemTypeDialog extends Dialog {
    @BindView(R.id.text_input)
    EditText textInput;
    @BindView(R.id.cancel)
    TextView cancel;
    @BindView(R.id.confirm)
    TextView confirm;
    @BindView(R.id.titleText)
    TextView titleText;

    private String title;
    private AddProblemTypeDialog diaLog;

    public interface onClickCancelButtonListener {
        public void onYesClick();
    }

    public interface onClickComfirmButtonListener {
        public void onComfirmClick();
    }

    public static AddProblemTypeDialog builder(Context context) {
        return new AddProblemTypeDialog(context, R.style.AddProblemTypeDialog);
    }


    private onClickCancelButtonListener onClickCancelButtonListener;
    private onClickComfirmButtonListener onClickComfirmButtonListener;

    public AddProblemTypeDialog onClickCancelButton(onClickCancelButtonListener onClickCancelButtonListener) {
        this.onClickCancelButtonListener = onClickCancelButtonListener;
        return this;
    }

    public AddProblemTypeDialog onClickComfirmButton(onClickComfirmButtonListener onClickComfirmButtonListener) {
        this.onClickComfirmButtonListener = onClickComfirmButtonListener;
        return this;
    }

    public AddProblemTypeDialog(@NonNull Context context) {
        super(context);
    }

    public AddProblemTypeDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    protected AddProblemTypeDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_probelm);
        ButterKnife.bind(this);
//        titleText = (TextView) findViewById(R.id.titleText);
//        cancel = (TextView) findViewById(R.id.cancel);
//        confirm = (TextView) findViewById(R.id.confirm);
        setCanceledOnTouchOutside(false);

        diaLog = this;

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickCancelButtonListener.onYesClick();
                diaLog.dismiss();
            }
        });
        titleText.setText(title);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickComfirmButtonListener.onComfirmClick();
            }
        });
    }

    //不能直接调用控件，这个时候还没有调用oncreat;控件还没绑定
    public AddProblemTypeDialog setTitleText(String title) {
        this.title = title;
        return this;
    }

    public AddProblemTypeDialog setHint() {
        return this;
    }

    /**
     * 取得输入框输入的文字
     *
     * @return 输入框的文字
     */
    public String getInputText() {
        return textInput.getText().toString();
    }


}
